package com.sinothk.server.support.author;

import io.jsonwebtoken.Claims;

import java.util.HashMap;
import java.util.Map;

public class TokenUtil {

    public static final long TIME_MIN_1 = 60L * 1000L;
    public static final long TIME_MIN_15 = 15L * 60L * 1000L;
    public static final long TIME_MIN_30 = 30L * 60L * 1000L;
    public static final long TIME_HOURS_1 = 60L * 60L * 1000L;
    public static final long TIME_HOURS_24 = 24L * 60L * 60L * 1000L;
    public static final long TIME_DAY_15 = 15 * 24L * 60L * 60L * 1000L;
    public static final long TIME_DAY_30 = 30 * 24L * 60L * 60L * 1000L;

//    public static void main(String[] args) {
//        Map<String, Object> claims = new HashMap<>();
//        claims.put("uid", "123456");
//        claims.put("user_name", "admin");
//        claims.put("nick_name", "X-rapido");
//
//        String token = createToken(claims, TokenUtil.TIME_MIN_15); //
//        System.out.println("token = " + token);
//
//        System.out.println("认证 = " + checkToken(token));
//
//        Claims claimsRst = getTokenInfo(token);
//        claimsRst.forEach((k, v) -> {
//                    System.out.println(k + " = " + v);
//                }
//        );
//    }

    public static String createToken(Map<String, Object> claimsInfo, long time) {
        return JwtUtil.createJWT(String.valueOf(System.currentTimeMillis()), "sinothk", "111", time, claimsInfo);
    }

    public static Claims getTokenInfo(String token) {
        return JwtUtil.parseJWT(token);
    }

    public static boolean checkToken(String token) {
        return JwtUtil.checkJWT(token, null);
    }
}
